package com.ptswitch.material.pages.user;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.ptswitch.material.model.common.Uzer;
import com.ptswitch.material.pages.base.MaterialBasePage;
import com.ptswitch.material.service.UserService;
import com.ptswitch.material.util.HlogConstants;

public class CreateUser extends MaterialBasePage {

    @Inject
    private UserService userSer;
    @Property
    private Uzer user;
    @InjectPage
    private ListUser listUser;

    @OnEvent(value = EventConstants.ACTIVATE)
    Object init() {
        user = new Uzer();
        return null;
    }

    @OnEvent(component = "add")
    Object add() {
        checkUserIsAdmin();
        user.md5password();
        userSer.save(user);
        hlog(HlogConstants.addUser, user);
        return listUser;
    }
}
